package io.github.hadyang.leetcode.offer;

import java.util.Stack;
import org.junit.Test;

/** @author haoyang.shi */
public class TwoStack {

  @Test
  public void test() {
    push(1);
    push(2);
    push(3);
    System.out.println(pop());
    System.out.println(pop());
    push(1);
    System.out.println(pop());
  }

  Stack<Integer> stack1 = new Stack<>();
  Stack<Integer> stack2 = new Stack<>();

  public void push(int node) {
    stack1.push(node);
  }

  public int pop() {
    if (stack2.isEmpty()) {
      while (!stack1.isEmpty()) {
        stack2.push(stack1.pop());
      }
    }

    return stack2.pop();
  }
}
